from typing import Optional, List
from pydantic import BaseModel, Field
from datetime import datetime


class BaseSchema(BaseModel):
    class Config:
        allow_population_by_field_name = True
        alias_generator = lambda x: ''.join(word.capitalize() if i else word for i, word in enumerate(x.split('_')))


class SysOperLogBase(BaseSchema):

    title: Optional[str] = Field(None, alias="title")

    business_type: Optional[int] = Field(None, alias="businessType")

    method: Optional[str] = Field(None, alias="method")

    request_method: Optional[str] = Field(None, alias="requestMethod")

    operator_type: Optional[int] = Field(None, alias="operatorType")

    oper_name: Optional[str] = Field(None, alias="operName")

    dept_name: Optional[str] = Field(None, alias="deptName")

    oper_url: Optional[str] = Field(None, alias="operUrl")

    oper_ip: Optional[str] = Field(None, alias="operIp")

    oper_location: Optional[str] = Field(None, alias="operLocation")

    oper_param: Optional[str] = Field(None, alias="operParam")

    json_result: Optional[str] = Field(None, alias="jsonResult")

    oper_status: Optional[int] = Field(None, alias="operStatus")

    status: Optional[str] = Field(None, alias="status")

    error_msg: Optional[str] = Field(None, alias="errorMsg")

    oper_time: Optional[datetime] = Field(None, alias="operTime")

    cost_time: Optional[int] = Field(None, alias="costTime")

    create_by: Optional[str] = Field(None, alias="createBy")

    create_time: Optional[datetime] = Field(None, alias="createTime")

    update_by: Optional[str] = Field(None, alias="updateBy")

    update_time: Optional[datetime] = Field(None, alias="updateTime")

    remark: Optional[str] = Field(None, alias="remark")



class SysOperLogCreate(SysOperLogBase):
    pass


class SysOperLogUpdate(SysOperLogBase):
    pass


class SysOperLogDelete(BaseModel):
    ids: List[int] = Field(..., description="操作日志记录ID列表")


class PageParams(BaseSchema):
    page_num: int = Field(1, ge=1, alias="pageNum", description="页码")
    page_size: int = Field(10, ge=1, le=100, alias="pageSize", description="每页数量")

    title: Optional[str] = Field(None, alias="title")

    method: Optional[str] = Field(None, alias="method")

    request_method: Optional[str] = Field(None, alias="requestMethod")

    oper_name: Optional[str] = Field(None, alias="operName")

    dept_name: Optional[str] = Field(None, alias="deptName")

    oper_url: Optional[str] = Field(None, alias="operUrl")

    oper_ip: Optional[str] = Field(None, alias="operIp")

    oper_location: Optional[str] = Field(None, alias="operLocation")

    oper_param: Optional[str] = Field(None, alias="operParam")

    json_result: Optional[str] = Field(None, alias="jsonResult")

    status: Optional[str] = Field(None, alias="status")

    error_msg: Optional[str] = Field(None, alias="errorMsg")

    create_by: Optional[str] = Field(None, alias="createBy")

    update_by: Optional[str] = Field(None, alias="updateBy")

    remark: Optional[str] = Field(None, alias="remark")
